﻿using System;
using System.Collections.Generic;

using E.Model;
using E.BLL;
using E.Web.UI.Page;

using X.Pager;
using X.Pager.List;
using X.Common;

namespace E.Web.Teacher.internals.question
{
    public partial class List : TeacherBasePage
    {
        public Dictionary<int, string> categoryList;
        public IList<ShortQuestionModel> questionList;
        public Dictionary<int, string> courseList;

        public string act;
        public string title;
        public int categoryid, courseid, isRequired;

        protected override void ShowPage()
        {
            QuestionBLL bll = new QuestionBLL();

            categoryList = bll.GetQuestionCategoryList();
            //courseList = (new CourseBLL()).GetCourseList();
            courseList = (new CourseBLL()).GetCourseListByTeacherID(teacherid);

            act = XRequest.GetString("act");
            title = XRequest.GetString("TitleTxt");
            categoryid = XRequest.GetInt("CategorySlt", -1);
            courseid = XRequest.GetInt("CourseSlt", -1);
            isRequired = XRequest.GetInt("IsRequiredSlt", -1);

            if (ispost || act == "s")
            {
                SearchQuestionModel searchModel = new SearchQuestionModel();
                searchModel.Title = title;
                searchModel.CategoryID = categoryid;
                searchModel.CourseID = courseid;
                searchModel.ProjectID = (new TeacherBLL()).GetTeacherProjectID(teacherid);
                searchModel.IsRequired = isRequired;

                QuestionListModel listModel = new QuestionListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));

                listModel = bll.GetInternalQuestionList(searchModel, customerPageSize, pageIndex);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    questionList = listModel.List;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("TitleTxt", title);
                    parms.Add("CategorySlt", categoryid.ToString());
                    parms.Add("CourseSlt", courseid.ToString());
                    mypager = pager.DrawPager("selfpager", parms);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
